package com.csproj.siiat.base.common.util;

import java.lang.reflect.Method;

/**
 * ==================================================
 * 创建人：gaohzh
 * 创建时间：2017/12/14
 * ==================================================
 * 类说明：
 * <p>
 * ==================================================
 *
 * @version 1.0 2017/12/14
 */
public class ReflectFactory<T>{
    private T object;
    private String methodName;
    private Class<?>[] parameterTypes;
    private Object[] parameter;

    public ReflectFactory<T> setObject(T object){
        this.object = object;
        return this;
    }
    public ReflectFactory setMethodName(String methodName){
        this.methodName=methodName;
        return this;
    }
    public ReflectFactory setParameterTypes(Class<?>... parameterTypes){
        this.parameterTypes=parameterTypes;
        return this;
    }
    public ReflectFactory setParameter(Object... parameter){
        this.parameter=parameter;
        return this;
    }

    public Object invoke(){
        try{
            Method getMethod = object.getClass().getMethod(methodName,parameterTypes);
            Object result = getMethod.invoke(object, parameter); // 调用getter方法获取属性值
            return result;
        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
